<?php  if (!defined('BASEPATH')) exit('No direct script access allowed');

session_start();
function checkLogin()
{
	$url_login =  'c_login';
	$url =  uri_string();
	if (! preg_match("/index.php\//", $_SERVER['REQUEST_URI'])){
		redirect (base_url());
	}
	$segment = explode('/',$url);
	if (@$_SESSION[SESSION_LOGIN] == 1){
		if (@$segment[1] == $url_login){
			if (@$segment[2] != 'logout')
				redirect(base_url());
		}
	}else{
		if (@$segment[1] != $url_login)
			redirect(base_url().'c_login');
	}
}

function setLogin($data){
	$_SESSION = $data;
	$_SESSION[SESSION_LOGIN] = 1;
}

function setLogout(){
	$_SESSION[SESSION_LOGIN] = 0;
	session_destroy();
	redirect(base_url());
}